package com.jewel.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.jewel.service.BlockService;


@Controller
public class CatalogBlockController {

    @Autowired
    private BlockService blockService;

    @RequestMapping(value = "/catalogBlock", method = RequestMethod.GET)
    public ModelAndView index(@RequestParam Integer blockId){
        ModelAndView modelAndView = new ModelAndView();

        modelAndView.addObject("block", this.blockService.getBlockById(blockId));
        modelAndView.addObject("products", this.blockService.getAllProductByBlockId(blockId));

        modelAndView.setViewName("catalogBlock");
        return  modelAndView;
    }
}
